package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.LogiProjectShipLineExtEditBo;
import com.piggy.logi.sys.vo.LogiProjectShipLineExtVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiProjectShipLineVo;
import com.piggy.logi.sys.bo.LogiProjectShipLineQueryBo;
import com.piggy.logi.sys.bo.LogiProjectShipLineEditBo;
import com.piggy.logi.sys.service.ILogiProjectShipLineService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;
import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 项目收发货线路管理Controller
 *
 * @author piggy
 * @date 2023-08-18
 */
@Api(value = "项目收发货线路管理控制器", tags = {"项目收发货线路管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/shipline")
public class LogiProjectShipLineController extends BaseController {

    private final ILogiProjectShipLineService iLogiProjectShipLineService;

    /**
     * 查询项目收发货线路管理列表
     */
    @ApiOperation("查询项目收发货线路管理列表")
    //@SaCheckPermission("sys:shipline:list")
    @GetMapping("/list")
    public TableDataInfo<LogiProjectShipLineExtVo> list(@Validated LogiProjectShipLineQueryBo bo) {
        return iLogiProjectShipLineService.queryPageList(bo);
    }

    /**
     * 导出项目收发货线路管理列表
     */
    @ApiOperation("导出项目收发货线路管理列表")
    //@SaCheckPermission("sys:shipline:export")
    @LogiLog(title = "项目收发货线路管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiProjectShipLineQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getMainDeptId());
        List<LogiProjectShipLineExtVo> list = iLogiProjectShipLineService.queryList(bo);
        ExcelUtil<LogiProjectShipLineExtVo> util = new ExcelUtil<LogiProjectShipLineExtVo>(LogiProjectShipLineExtVo.class);
        util.exportExcel(response, list, "项目收发货线路管理");
    }

    /**
     * 获取项目收发货线路管理详细信息
     */
    @ApiOperation("获取项目收发货线路管理详细信息")
    //@SaCheckPermission("sys:shipline:query")
    @GetMapping("/{id}")
    public R<LogiProjectShipLineExtVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") String id) {
        return R.ok(iLogiProjectShipLineService.queryById(id, SecurityUtils.getMainDeptId()));
    }

    /**
     * 新增项目收发货线路管理
     */
    @ApiOperation("新增项目收发货线路管理")
    //@SaCheckPermission("sys:shipline:add")
    @LogiLog(title = "项目收发货线路管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Integer> add(@Validated @RequestBody LogiProjectShipLineExtEditBo bo) {
        return R.ok(iLogiProjectShipLineService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改项目收发货线路管理
     */
    @ApiOperation("修改项目收发货线路管理")
    //@SaCheckPermission("sys:shipline:edit")
    @LogiLog(title = "项目收发货线路管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Integer> edit(@Validated @RequestBody LogiProjectShipLineExtEditBo bo) {
        return R.ok(iLogiProjectShipLineService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除项目收发货线路管理
     */
    @ApiOperation("删除项目收发货线路管理")
    //@SaCheckPermission("sys:shipline:remove")
    @LogiLog(title = "项目收发货线路管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiProjectShipLineService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
